<script setup>
import NavBar from '../../components/nav-bar'
	import DetailBody from './c-cpns/detail-body.vue'
	import {onLoad} from "@dcloudio/uni-app"
	import {ref,reactive} from 'vue'
	let taskInfo = ref({})
	let joinTask = ref('立即报名')
	let options = reactive()
	onLoad((item) => {
		options=item,
    // console.log(options.id);  
		getShow()
	})
	function getShow(){
	    uni.request({
			url:`https://tp6.recer.starsky.fun//api/Home/Task/show?mid=52248&tid=${options.id}`,
			method: "POST",
			header: {
				'content-type': 'application/json; charset=utf-8' //重点
			},
			success: (res) => {
				taskInfo.value=res.data.data.show
				console.log(taskInfo);
			}
		})
	}
	const showMsg = () => {
		let myleval = 0
		const mid = uni.getStorageSync('mid')
		if (!uni.getStorageSync('mid')) {
			//如果登录的情况下，通过mid获取用户的等级
			// uni.request({
			// 	url:'...',
			// 	data:{
			// 		mid:mid
			// 	},
			// 	header: {
			// 		'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
			// 	},
			// 	method:'GET',
			// 	success:(res)=> {
			// 		//返回用户的等级
			// 		if(res.data.data.leval=='初级达人') {
			// 			myleval = 0
			// 		}
			// 		else if(res.data.data.leval=='中级达人') {
			// 			myleval = 1
			// 		}
			// 		else {
			// 			myleval = 2
			// 		}
			// 	}
			// })
		}
	
		if (!uni.getStorageSync('mid')) {
			uni.showToast({
				title: '请您先登录',
				icon: 'none',
				duration: 2000
			});
		}
		//判断会员等级是否小于任务等级
		// else if(myleval<taskLeval){
		// 	uni.showToast({
		// 		title: '您的会员等级不能领取高级达人的任务',
		// 		icon:'none',
		// 		duration: 2000
		// 	});
		// }
		else {
      // console.log(taskId)
			//满足登录且会员等级足够时，提交mid和taskid，报名成功
			uni.request({
				url: 'http://recommender.starsky.fun/Home/Task/get_task.html',
				data: {
					mid: mid,
					taskId: options.id
				},
				method: 'POST',
				header: {
					'content-type': 'application/json; charset=utf-8'
				},
				success: (res) => {
	
				}
			})
			uni.showToast({
				title: '报名成功',
				icon: 'none',
				duration: 2000
			})
			joinTask.value = '已领取,商家审核中'
		}
	}
	// 手机状态栏的高度
	const {
		statusBarHeight
	} = uni.getSystemInfoSync()
</script>

<template>
  <view class="detail-content">
    <view class="statusBarHeight"  :style="{ height: statusBarHeight * 2 + 'rpx' }"></view>
    <nav-bar title="任务详情" />
    <detail-body  :taskInfo="taskInfo"/>
    <view class="bottom-btn" @click="showMsg">{{joinTask}}</view>
  </view>
</template>

<style lang="scss" scoped>
.detail-content {
  height: 100vh;
  background-color: #f0f0f0;

  .statusBarHeight {
    background-color: #faca2a;
  }

  .bottom-btn {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 88rpx;
    background-color: #faca2a;
    line-height: 88rpx;
    text-align: center;
  }
}
</style>